package net.pulseproject.commons.misc.collection;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

public abstract class Filter<T> {

	protected final Collection<T> filter(final Collection<T> allItems, final Matcher<T> matcher) {
		if(allItems == null) { throw new IllegalArgumentException("allItems == null"); }
		if(matcher == null) { throw new IllegalArgumentException("matcher == null"); }
		
		final Collection<T> filteredItems = new LinkedList<T>();
		
		for (final T currentItem : allItems) {
			if(matcher.matches(currentItem) == true) {
				filteredItems.add(currentItem);
			}
		}
		
		return Collections.unmodifiableCollection(filteredItems);
	}
	
}
